package hongcaosp.app.android.contact;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import hongcaosp.app.android.R;
import hongcaosp.app.android.comment.IViewType;
import hongcaosp.app.android.common.BaseAdapter;
import hongcaosp.app.android.common.BaseHolder;
import hongcaosp.app.android.contact.friends.OnFriendClickListener;

public class ContactAdapter extends BaseAdapter<IViewType> {
    private Context context;
    private OnFriendClickListener friendClickListener;

    public ContactAdapter(Context context, OnFriendClickListener friendClickListener) {
        this.context = context;
        this.friendClickListener = friendClickListener;
    }

    @NonNull
    @Override
    public BaseHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == IViewType.VIEWTYPE_CONTACT) {
            return new ContactHolder(context,LayoutInflater.from(context).inflate(R.layout.item_contact,parent,false), friendClickListener);
        } else if (viewType == IViewType.VIEWTYPE_HEAD) {
            return new HeadHolder(LayoutInflater.from(context).inflate(R.layout.item_header,parent,false));
        }
        return null;
    }

    @Override
    public int getItemViewType(int position) {
        IViewType viewType = getItem(position);
        return viewType.viewType();
    }
}
